package org.joshsacks.fishies;

import org.joshsacks.fishies.GameBoard.MatchSet;
import org.joshsacks.fishies.GameBoard.MatchSet.Match;


public class Score {
  private static int[] SCORES = 
    {300, 500, 1000, 2000, 5000, 12000, 25000, 50000, 120000};
  private int totalScore;
  private int previousMatches = 0;
  
  public void resetPreviousMatches() {
    previousMatches = 0;
  }
  
  public void addMatch(MatchSet matchSet) {
    if (matchSet.isEmpty()) {
      previousMatches = 0;
      return;
    }
    
    for (Match match : matchSet.getMatches()) {
      totalScore += getScoreForMatch(match); 
    }    
    
    previousMatches++;
  }

  public int getScoreForMatch(Match match) {  
    int length = match.getLength() - 3;
    if (length >= SCORES.length) {
      return SCORES[SCORES.length] << (length - SCORES.length + 1 + previousMatches);
    } else {
      return SCORES[length] << previousMatches;
    }
  }

  public int getScore() {
    return totalScore;
  }
}